#include "StringUtil.h"

#include <locale>

using namespace std;
using namespace Hiranipra;

typedef ctype<wchar_t> ctwide;

const string Hiranipra::NarrowString( const wstring& wstr )
{
    string narrow( wstr.length(), '\0' );
    ctwide const& ct = use_facet< ctwide >( locale() );
    ct.narrow( &wstr[0], &wstr[0] + wstr.length(), '_', &narrow[0] );
    return narrow;
}

const wstring Hiranipra::WidenString( const string& str )
{
    wstring wide( str.length(), L'\0' );
    ctwide const& ct = use_facet< ctwide >( locale() );
    ct.widen( &str[0], &str[0] + str.length(), &wide[0] );
    return wide;
}
